import Generation,UMap,Clustering,Decoding,InternalBallistic,Analysis,BestMatchingInPSFD
import os
from DDPM.Evaluation.Control import *
from DEAD.AutoDecoder.Config import model_load_path as dead_model_load_path

def get_sorted_py_files(folder_path):
    # 获取文件夹下所有 .py 文件，并去掉后缀
    py_files = [f[:-3] for f in os.listdir(folder_path) if f.endswith('.py')]
    
    # 对文件名进行排序（默认按字母顺序）
    py_files.sort()
    
    return py_files

if __name__ == "__main__":
    question_lib = get_sorted_py_files("DDPM/Evaluation/逆向设计问题")
    print(question_lib)

    # ===============探寻最佳的guid_w================
    for guidw in [0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]:
        control_params=get_control_params(question_name="E短巡航双推力装药",
            postfix="_epoch50000",
            cluster_num=5,
            guid_w=guidw,
            seed=123)
        Generation.start_generation(control_params)
        UMap.start_umap(control_params)
        Clustering.start_post_processing(control_params, dead_model_load_path)
        Decoding.start_decoding(control_params)
        InternalBallistic.start_internal_ballistic_cal(control_params)
        Analysis.start_analysis(control_params)
    
    # ===========重复试验9次，验证可重复性=============
    for seed in [456, 789, 101, 112, 1130, 1124, 1915, 11006, 1187]:
        control_params=get_control_params(question_name="E短巡航双推力装药",
            postfix="_epoch50000",
            cluster_num=5,
            guid_w=0.3,
            seed=seed)
        Generation.start_generation(control_params)
        UMap.start_umap(control_params)
        Clustering.start_post_processing(control_params, dead_model_load_path)
        Decoding.start_decoding(control_params)
        InternalBallistic.start_internal_ballistic_cal(control_params)
        Analysis.start_analysis(control_params)

    # ===========完成所有测试案例的计算=============
    for question_name in question_lib:
        control_params=get_control_params(question_name=question_name,
            postfix="_epoch50000",
            cluster_num=5,
            guid_w=0.3,
            seed=123)
        Generation.start_generation(control_params)
        UMap.start_umap(control_params)
        Clustering.start_post_processing(control_params, dead_model_load_path)
        Decoding.start_decoding(control_params)
        InternalBallistic.start_internal_ballistic_cal(control_params)
        Analysis.start_analysis(control_params)
        BestMatchingInPSFD.start_find_best_in_psfd(control_params)